input_file = '/Users/xubing/Code/Projects/questionnaire/log_processor/questionnaire.log'
output_file = '/Users/xubing/Code/Projects/questionnaire/log_processor/filtered_questionnaire.log'

with open(input_file, 'r', encoding='utf-8') as f_in, open(output_file, 'w', encoding='utf-8') as f_out:
    is_questionnaire_chat = False
    for line in f_in:
        if '[route]:' in line and 'questionnaire_chat' in line:
            is_questionnaire_chat = True
        elif '[route]:' in line and 'questionnaire_chat' not in line:
            is_questionnaire_chat = False
        if is_questionnaire_chat and '[response_data]' in line:
            f_out.write(line)